package xyz.zdsoft.project_group_manage_module.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.zdsoft.common.utils.Result;
import xyz.zdsoft.project_group_manage_module.service.InsertStudentToTeamGchService;
import javax.annotation.Resource;
import java.util.HashMap;
@RestController
@Api(tags = "项目组管理")
public class AdminInsertStudentToTeamController {
    @Resource
    private InsertStudentToTeamGchService insertStudentToTeamGchService;

    @ApiOperation("项目组添加学员(可批量)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teamName",value = "小组名称",required = true,example ="JAVA小组"),
            @ApiImplicitParam(name = "studentIds",value = "学生id,若有多个则用','隔开",required = true,example ="200")
    })
    @PostMapping("/InsertStudentToTeam")
    public Result insertStudentToTeam(String teamName,Long[] studentIds){
        HashMap<String,Object> map=new HashMap<>();
        map.put("teamName",teamName);
        Integer num=0;
        for (Long studentId:studentIds ){
            map.put("studentId",studentId);
            if (insertStudentToTeamGchService.SelStudentIsHave(studentId)>0){
                if (insertStudentToTeamGchService.SelTeamHaveStudent(map)>0){
                    return Result.error().message("第"+num+1+"位学员已在小组中");

                }
                else num+= insertStudentToTeamGchService.InsertStudentInTeam(map);

            }
            else return Result.error().message("新增的学员不存在");


        }
        if (num>0){
            return Result.ok().message("新增了"+num+"个学生");
        }
        else return Result.error().message("新增失败");


    }

}
